<template>
    <div>
        <a href="/Add">XINZENG</a>
        姓名:<input type="text" v-model="ts.name">
        日期:<input type="date" v-model="ts.d1">-<input type="date" v-model="ts.d2">
        <input type="button" value="查询" @click="xx">
        <input type="button" value="重置" @click="xxx">
        <table class="table">
            <thead>
                <tr>
                    <td>编号</td>
                    <td>姓名</td>
                    <td>人数</td>
                    <td>描述</td>
                    <td>日期</td>
                    <td>是否删除</td>
                    <td>操作</td>
                </tr>
            </thead>
            <tbody>
                <tr v-for="a in date">
                    <td>{{ a.insenId }}</td>
                    <td>{{ a.insenName }}</td>
                    <td>{{ a.preame }}</td>
                    <td>{{ a.miaoshu }}</td>
                    <td>{{ moment(a.creates).format("YYYY-MM-DD HH:MM:SS") }}</td>
                    <td>{{ a.isDelete }}</td>
                    <td>
                        <input type="button" value="删除" @click="del(a.insenId)">
                        <input type="button" value="编辑" @click="upd(a.insenId)">
                    </td>
                </tr>
            </tbody>
        </table>

    </div>
</template>

<script setup lang="ts">
import { ref,onMounted } from 'vue';
import { useRouter } from 'vue-router';
import axios from 'axios';
import moment from 'moment';
const routher = useRouter();
onMounted(()=>{
    show()
})
const upd=(val:any)=>{
    routher.push({path:"/Update",query:{id:val}});
}
const del=(val:any)=>{
    if(!confirm("确认删除吗")){
        return
    }
    axios.delete("https://localhost:7223/api/Insen/InDelete",{params:{id:val}}).then(res=>{
        if(res.data>0){
            alert("删除成功")
            show()
        }
        else{
            alert("删除是比")
        }
    })
}
const xx=()=>{
    show();
}
const xxx=()=>{
    ts.value={
        name:'',
        d1:null,
        d2:null
    }
    show()
}
const ts=ref({
    name:'',
    d1:null,
    d2:null
})
const show=()=>{
    axios.get("https://localhost:7223/api/Insen/Show",{params:ts.value}).then(res=>{
        date.value=res.data
    })
}
const date=ref([{
  "insenId": 0,
  "insenName": "",
  "preame": 0,
  "miaoshu": "",
  "creates": "",
  "isDelete": false
}])
</script>

<style scoped>

</style>